

#include "userUI.h"

#include "CRC8_CRC16.h"
#include "referee.h"
#include "string.h"
#include "usart.h"
#include "bsp_usart.h"
#include "CRC.h"

//#include "sound_effects_task.h"


extern UART_HandleTypeDef huart6;


/**
  * @brief          自定义UI绘制背景元素
  * @param[in]      none
  * @retval         none
  */
void userUI_draw_background(void)
{
    static uint8_t client_data[120];
    static ext_client_custom_graphic_single_t  data;

    //画恒功率电源余量指示条外框
    data.frame_head.SOF = 0xA5;
    //data.frame_head.data_length = 21;
    data.frame_head.data_length = sizeof(data.grapic_data_struct) + sizeof(data.student_interactive_header_data);
    data.frame_head.seq = 0;
    data.cmd_id = 0x0301;
    data.student_interactive_header_data.data_cmd_id = 0x0101;
    data.student_interactive_header_data.sender_ID = get_robot_id();
    data.student_interactive_header_data.receiver_ID = get_robot_client_id();
    data.grapic_data_struct.graphic_name[0] = 'E';
    data.grapic_data_struct.graphic_name[1] = 'C';
    data.grapic_data_struct.graphic_name[2] = 'B';
    data.grapic_data_struct.operate_tpye = 1;      //增加
    data.grapic_data_struct.graphic_tpye = 1;      //矩形
    data.grapic_data_struct.layer = 0;             //图层0
    data.grapic_data_struct.color = 1;             //阵营颜色（红/蓝)
    data.grapic_data_struct.start_angle = 0;
    data.grapic_data_struct.end_angle = 0;
    data.grapic_data_struct.width = 3;             //线宽
    //data.grapic_data_struct.start_x = 480;         //起始坐标X
    //data.grapic_data_struct.start_y = 1000;        //起始坐标Y
    //data.grapic_data_struct.radius = 0;
    //data.grapic_data_struct.end_x = 1440;          //终点坐标X
    //data.grapic_data_struct.end_y = 1020;          //终点坐标Y
    data.grapic_data_struct.start_x = 480;         //起始坐标X
    data.grapic_data_struct.start_y = 500;        //起始坐标Y
    data.grapic_data_struct.radius = 0;
    data.grapic_data_struct.end_x = 1440;          //终点坐标X
    data.grapic_data_struct.end_y = 600;          //终点坐标Y

    memcpy(client_data, &data, sizeof(data));

    append_CRC8_check_sum(client_data, 5);
    append_CRC16_check_sum(client_data, sizeof(data));

    //HAL_UART_Transmit_DMA(REFEREE_UART, client_data, sizeof(data));
   // usart6_tx_dma_enable(client_data,sizeof(data));
}


void client_send_data()
{
    static uint8_t client_data[120];
    static ext_client_custom_graphic_single_t  ext_client_custom_graphic_single;

    ext_client_custom_graphic_single.frame_head.SOF = 0xA5;
    ext_client_custom_graphic_single.frame_head.data_length = 21;
    ext_client_custom_graphic_single.frame_head.seq = 0;
    ext_client_custom_graphic_single.cmd_id = 0x0301;
    ext_client_custom_graphic_single.student_interactive_header_data.data_cmd_id = 0x0101;
    ext_client_custom_graphic_single.student_interactive_header_data.sender_ID = get_robot_id();
    ext_client_custom_graphic_single.student_interactive_header_data.receiver_ID = get_robot_client_id();
    ext_client_custom_graphic_single.grapic_data_struct.graphic_name[0] = 0x01;
    ext_client_custom_graphic_single.grapic_data_struct.graphic_name[1] = 0x01;
    ext_client_custom_graphic_single.grapic_data_struct.graphic_name[2] = 0x01;
    ext_client_custom_graphic_single.grapic_data_struct.operate_tpye = 1;
    ext_client_custom_graphic_single.grapic_data_struct.graphic_tpye = 0;
    ext_client_custom_graphic_single.grapic_data_struct.layer = 0;
    ext_client_custom_graphic_single.grapic_data_struct.color = 2;
    ext_client_custom_graphic_single.grapic_data_struct.start_angle = 0;
    ext_client_custom_graphic_single.grapic_data_struct.end_angle = 0;
    ext_client_custom_graphic_single.grapic_data_struct.width = 2;
    ext_client_custom_graphic_single.grapic_data_struct.start_x = 610;
    ext_client_custom_graphic_single.grapic_data_struct.start_y = 900;
    ext_client_custom_graphic_single.grapic_data_struct.radius = 0;
    ext_client_custom_graphic_single.grapic_data_struct.end_x = 1295;
    ext_client_custom_graphic_single.grapic_data_struct.end_y = 900;

    memcpy(client_data, &ext_client_custom_graphic_single, sizeof(ext_client_custom_graphic_single));


    //Append_CRC8_Check_Sum(client_data, 5);
   // Append_CRC16_Check_Sum(client_data, sizeof(ext_client_custom_graphic_single));
    //HAL_UART_Transmit_DMA(&REFEREE_HUART, client_data, sizeof(ext_client_custom_graphic_single));
    //usart6_tx_dma_enable(client_data, sizeof(ext_client_custom_graphic_single));
}


void client_send_data1()
{
    static uint8_t client_data[120];
    static ext_client_custom_graphic_single_t  ext_client_custom_graphic_single;


    ext_client_custom_graphic_single.frame_head.SOF = 0xA5;
    ext_client_custom_graphic_single.frame_head.data_length = 21;
    ext_client_custom_graphic_single.frame_head.seq = 0;
    ext_client_custom_graphic_single.cmd_id = 0x0301;
    ext_client_custom_graphic_single.student_interactive_header_data.data_cmd_id = 0x0101;
    ext_client_custom_graphic_single.student_interactive_header_data.sender_ID = get_robot_id();
    ext_client_custom_graphic_single.student_interactive_header_data.receiver_ID = get_robot_client_id();
    ext_client_custom_graphic_single.grapic_data_struct.graphic_name[0] = 0x01;
    ext_client_custom_graphic_single.grapic_data_struct.graphic_name[1] = 0x01;
    ext_client_custom_graphic_single.grapic_data_struct.graphic_name[2] = 0x01;
    ext_client_custom_graphic_single.grapic_data_struct.operate_tpye = 2;
    ext_client_custom_graphic_single.grapic_data_struct.graphic_tpye = 0;
    ext_client_custom_graphic_single.grapic_data_struct.layer = 0;
    if (2100 > 2000)
        ext_client_custom_graphic_single.grapic_data_struct.color = 2;
    else
        ext_client_custom_graphic_single.grapic_data_struct.color = 3;
    ext_client_custom_graphic_single.grapic_data_struct.start_angle = 0;
    ext_client_custom_graphic_single.grapic_data_struct.end_angle = 0;
    ext_client_custom_graphic_single.grapic_data_struct.width = 20;
    ext_client_custom_graphic_single.grapic_data_struct.start_x = 610;
    ext_client_custom_graphic_single.grapic_data_struct.start_y = 900;
    ext_client_custom_graphic_single.grapic_data_struct.radius = 0;
    ext_client_custom_graphic_single.grapic_data_struct.end_x = 610 + 2100 - 1600;
    if (ext_client_custom_graphic_single.grapic_data_struct.end_x < 610)
        ext_client_custom_graphic_single.grapic_data_struct.end_x = 610;
    ext_client_custom_graphic_single.grapic_data_struct.end_y = 900;

    memcpy(client_data, &ext_client_custom_graphic_single, sizeof(ext_client_custom_graphic_single));

    //Append_CRC8_Check_Sum(client_data, 5);
    //Append_CRC16_Check_Sum(client_data, sizeof(ext_client_custom_graphic_single));
    //HAL_UART_Transmit_DMA(&REFEREE_HUART, client_data, sizeof(ext_client_custom_graphic_single));
    //usart6_tx_dma_enable(client_data, sizeof(ext_client_custom_graphic_single));
}

